package com.jinghao.tws.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import com.jinghao.core.common.exception.JingHaoCustomerException;
import com.jinghao.core.common.service.impl.JingHaoBaseServiceImpl;
import com.jinghao.core.common.util.cnd.JhCnd;
import com.jinghao.tws.service.IWvCloudAccessConfigService;
import com.jinghao.tws.entity.WvCloudAccessConfig;

@Service("wvCloudAccessConfigService")
public class WvCloudAccessConfigServiceImpl extends JingHaoBaseServiceImpl<WvCloudAccessConfig> implements IWvCloudAccessConfigService {
	//==================定制内容开始======================
//在这里修改代码
	@Override
	public void getWvCloudAccessConfig(WvCloudAccessConfig model) {
		model.setMapList(this.queryMapList(model));
	}

	@Override
	public void addWvCloudAccessConfig(WvCloudAccessConfig model) {
		List<Map<String,Object>> list=this.queryMapList(model);
		if (StringUtils.isEmpty(model.getAddress())) {
			throw new JingHaoCustomerException("云IP地址不能为空！");
		}
		if (StringUtils.isEmpty(model.getUsername())) {
			throw new JingHaoCustomerException("云用户名不能为空！");
		}
		if (StringUtils.isEmpty(model.getPassword())) {
			throw new JingHaoCustomerException("云用户密码不能为空！");
		}
		if (StringUtils.isEmpty(model.getStorehousecode())) {
			throw new JingHaoCustomerException("仓库编码不能为空！");
		}
		
		if (!StringUtils.isEmpty(model.getFtpAddress())) {
			if (model.getFtpPort()==null) {
				throw new JingHaoCustomerException("ftp端口不能为空！");
			}
			if (StringUtils.isEmpty(model.getFtpUsername())) {
				throw new JingHaoCustomerException("ftp账户名不能为空！");
			}
			if (StringUtils.isEmpty(model.getFtpPassword())) {
				throw new JingHaoCustomerException("ftp账户密码不能为空！");
			}
			if (StringUtils.isEmpty(model.getLocalFileDirectory())) {
				throw new JingHaoCustomerException("本地视频目录不能为空！");
			}
		}
		
		if (!StringUtils.isEmpty(model.getCacUuid())) {
			//删除历史数据
			if(list!=null&&list.size()>0){
				JhCnd cnd=new JhCnd();
				cnd.andEquals("cacUuid");  
				model.setJhCnd(cnd);
				this.deleteSame(model);
			}
		}
		//保存数据
		model.setCacUuid(model.getUUID());
		this.add(model);
	}
	
	//==================定制内容结束======================
}
